// pages/auth/index.js
import { login } from "../../utils/asyncWX.js";
import { request } from "../../request/index.js";
import regeneratorRuntime from "../../lib/runtime/runtime";

Page({
  data: {

  },
  // 获取用户信息
  async handleGetUserInfo(e) {
    try {
      const { encryptedData, rawData, iv, signature } = e.detail
      const { code } = await login()
      const loginParams = { encryptedData, rawData, iv, signature, code }
      // 没有企业appid无法获得token
      const { token } = await request({ url: '/users/wxlogin', data: loginParams, method: 'post' })
      wx.setStorageSync('token', token);
      wx.navigateBack({
        delta: 1
      })
    } catch (error) {
      console.log(error);
    }
  }
})